import java.util.*;

public class 自定义优先队列的排序规则 {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		int n = sc.nextInt();
		var q = new PriorityQueue<pair2>();
		for(int i = 1; i <= n; i ++ ) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			q.add(new pair2(x, y));
		}
		while(!q.isEmpty()) {
			var t = q.poll();
			System.out.print(t.x + " " + t.y + "\n");
		}
	}
}

class pair2 implements Comparable<pair2>{

	int x;
	int y;
	public pair2(int x, int y) {
		this.x = x;
		this.y = y;
	}
	@Override
	public int compareTo(pair2 o) {
		if(this.x != o.x) { // 按照x从小到大进行排序
			return this.x - o.x;
		}
		return o.y - this.y; // 否则的话 按照y进行从大到小进行排序
	}
	
}
